import java.util.*;
public class db_result_dataset implements db_interface_result{
	private int iRowCnt = 0;
	private ArrayList<db_column> oCols = null;
	private byte[] bData = null;
	
	db_result_dataset (ArrayList<db_column> oColumns, int iRowCount, byte[] bDataSet) {
		oCols = oColumns;
		iRowCnt = iRowCount; 
		bData = bDataSet;
	}
	public byte[] getBytes() {
		// 4 byte for number of columns. 
		// Then 4 + 4 + 4 = 12 for col type, length of type, and length of the column name 
		// Then 4 for number of rows and finally length of the row data
		int iSize = 4 + 4 + oCols.size() * (12) + 4 + bData.length;
		for (int i = 0; i < oCols.size(); i++)
			iSize += oCols.get(i).sName.length();
		byte[] bHeaders = ("200 OK QDBP/1.0\nlength: " + iSize + "\n\n").getBytes();
		db_bytes oOut = new db_bytes(iSize + bHeaders.length);

		oOut.write(bHeaders);
		oOut.write(db_util.DB_RESULT_DATASET);
		oOut.write(oCols.size());
		
		for (int i = 0; i < oCols.size(); i++) {
			
			oOut.write((int)oCols.get(i).lType);
			oOut.write((int)oCols.get(i).lLength);
			oOut.write(oCols.get(i).sName);
		}

		

		oOut.write(iRowCnt);
		oOut.write(bData);
	
		return oOut.getBytes(); 
	}
}
